package Server;

import java.util.Map;
import java.util.TreeMap;
import java.util.List;
import java.util.Collection;
import java.util.ArrayList;

import sql.Main;

// THIS IS THE APPLICATION SERVICE CLASS
public class TralalaService {
	
	Main m=null;
	
	private static TralalaService instance=null;
	
	private TralalaService()  {
		
		m= new Main();
	}

	public static TralalaService getInstance(){
		if(instance==null){
			instance=new TralalaService();
		}else{
			
		}
		return instance;
	}
		
	public synchronized Server.Song SendASong(String title){
		
		System.out.println("Llego al server");
		Song song=null;
		song=m.returnSong(title);
		//song=new Song(1,"Danza Kuduro","???","Don Omar");
		if(song.getTitulo().equals(title)){
			return song;
		}else{
			return null;
		}
		
       
	}
	

	public synchronized Server.SongDTO[] SendSongs(){
		
		
		
			SongDTO[] songs=null;

			ArrayList<Song>sl=m.returnSongs();
			//ArrayList<Song>sl = new ArrayList<Song>();
			//Song song=new Song(1,"Danza Kuduro","???","Don Omar");
			//sl.add(song);
			songs= new SongDTO[sl.size()];
			for(int i=0;i<sl.size();i++){
				Song s=sl.get(i);
				songs[i]=new SongDTO(s.getTitulo(),s.getArtist());
			}
			return songs;
		
		
       
}
}
